package com.peng.edu.controller;


import com.peng.edu.entity.subject.OneSubject;
import com.peng.edu.service.SubjectService;
import com.peng.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Dengp
 * @since 2022-06-14
 */
@RestController
@RequestMapping("/edu/subject")
@CrossOrigin
public class SubjectController {
    @Autowired
    private SubjectService subjectService;

    //上文文件，获取文件将文件内容写入数据库
    @PostMapping("/addSubject")
    public Result addSubject(MultipartFile file){
        subjectService.addSubject(file);
        return Result.ok();
    }

    //课程分类列表（树形）
    @ApiOperation(value = "嵌套数据列表")
    @GetMapping("/getAllSubject")
    public Result getAllSubject(){
        List<OneSubject> list= subjectService.getAllSubject();
        HashMap<String, Object> map = new HashMap<>();
        map.put("list",list);
        return Result.ok().data(map);
    }

}

